package com.link.base.base.message.controller;

import com.link.base.base.message.model.MessagePublish;
import com.link.base.base.message.service.MessagePublishService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.controller.BasicControllerException;
import com.link.core.basic.service.BasicService;
import com.link.core.cllog.LCLogger;
import com.link.core.util.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 消息发布-维护发布消息 
 *
 * @author ouyangzhenqiang
 * @date 2019/07/25 13:16
 */
@Controller
@RequestMapping("/link/messagePublish")
public class MessagePublishController extends BasicController<MessagePublish> {

    @Resource
    private MessagePublishService messagePublishService;

    @Override
    public BasicService<MessagePublish> getBasicService() throws Exception {
        return messagePublishService;
    }

    /**
     * 消息发布
     *
     * @author ouyangzhenqiang
     * @date 2019/07/25 13:26
     */
    @GetMapping(value = "/publishMessage", produces = "application/json")
    @ResponseBody
    public Map<String, Object> publishMessage(HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<>(2);
        try {
            String id = request.getParameter("id");
            if (StringUtils.isBlank(id)) {
                throw new BasicControllerException("Id不能为空！");
            }
            messagePublishService.publishMessage(Long.parseLong(id));
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }


}
